package com.its.search.customer;

import com.its.goods.pojo.Goods;
import com.its.rabbitMq.vo.MyMessage;
import com.its.search.service.SearchService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GoodsToEsCustomer {
    //依赖注入业务层对象
    @Autowired
    private SearchService service;


    //创建监听方法: 新增商品文档数据
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue("goodsEsAdd"),
                    exchange = @Exchange(name = "goodsEs.exchange"),
                    key = {"goodsEsAdd.routingKey"}
            )
    })
    public void goodsToEsCustomerMessage(MyMessage<Goods> message) {
        service.syncGoodsToES(message.getGoodsDesc());
    }


    //创建监听方法:删除商品文档数据
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue("goodsEsDelete"),
                    exchange = @Exchange(name = "goodsEs.exchange"),
                    key = {"goodsEsDelete.routingKey"}
            )
    })
    public void deleteCustomerMessage(MyMessage message) {
        service.deleteGoodsService(message.getId());
    }
}
